package 题目集.hash;

import java.util.Scanner;

public class 水题2 {
    public static final boolean[] check=new boolean[10];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        check[2]=true;
        check[0]=true;
        check[1]=true;
        check[9]=true;
        long sum=0;
        for (int i = 1; i <= n; i++) {
            if(check(i)){
                sum+=i;
            }
        }
        System.out.println(sum);
    }
    public static boolean check(int n){
        while(n>0){
            if(check[n%10]){
                return true;
            }
            n/=10;
        }
        return false;
    }
}
